package Model;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;


/**
 * 
 * 
 * @author antoinerichard
 * 
 * Informations à propos d'un contact du carnet d'adresse
 *
 */
public class Person {
	
	private String name, firstName, companyAdress, phoneNumber, homePage, email, group, imageURL;
	private Date date;
	
	
/**
 * Constructeur avec géneration àleatoire
 * @deprecated
 */
	
	public Person()
	{
		char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
		Random rd= new Random();
		char[] rdName=new char[5];
		for(int i = 0;i<5;i++)
		{
			rdName[i]=chars[rd.nextInt(chars.length)];
		}
		
		
		this.name=new String(rdName);
		this.firstName="John";
		this.companyAdress="123 rue springfield";
		this.phoneNumber="555-555-555";
		this.homePage="www.ece.fr";
		this.email="doe@ece.fr";
		this.group="Friends";
		this.date=new Date();

	}
	
	/**
	 * Constructeur pour la création d'un nouveau contact
	 * @param nom
	 * @param prenom
	 * @param compagnieAdresse
	 * @param telephone
	 * @param siteWeb
	 * @param adresseMail
	 * @param groupe
	 */
	public Person(String nom, String prenom, String compagnieAdresse, String telephone, String siteWeb, String adresseMail, String groupe)
	{
		this.name=nom;
		this.firstName=prenom;
		this.companyAdress=compagnieAdresse;
		this.phoneNumber=telephone;
		this.homePage=siteWeb;
		this.email=adresseMail;
		this.group=groupe;
		this.date=new Date();
		this.imageURL=this.date.toString()+".png";
		System.out.println(this.imageURL);
	}
	
	

	/**
	 * Constructeur pour la creation de nouveaux contacts depuis le CSV
	 * @param nom
	 * @param prenom
	 * @param compagnieAdresse
	 * @param telephone
	 * @param siteWeb
	 * @param adresseMail
	 * @param groupe
	 * @param dateCrea
	 */
	public Person(String nom, String prenom, String compagnieAdresse, String telephone, String siteWeb, String adresseMail, String groupe,Date dateCrea)
	{
		this.name=nom;
		this.firstName=prenom;
		this.companyAdress=compagnieAdresse;
		this.phoneNumber=telephone;
		this.homePage=siteWeb;
		this.email=adresseMail;
		this.group=groupe;
		this.date=dateCrea;
		this.imageURL="Resources/"+this.fileDate(this.date)+".png";
		
	}
	
	/**
	 * Concatenation du nom et prenom
	 */
	public void displayName()
	{
		System.out.println(this.name+" "+this.firstName);
	}
	

	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	public String toString()
	{
		return (name +" "+firstName);
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @return the companyAdress
	 */
	public String getCompanyAdress() {
		return companyAdress;
	}

	/**
	 * @return the phoneNumber
	 */
	public String getPhoneNumber() {
		return phoneNumber;
	}

	/**
	 * @return the homePage
	 */
	public String getHomePage() {
		return homePage;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @return the group
	 */
	public String getGroup() {
		return group;
	}
	
	
	/**
	 * @return the group
	 */
	public String getDateToString() {
		 
		SimpleDateFormat formatDateJour = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS"); 
		String dateFormatee = formatDateJour.format(this.date); 
		return dateFormatee;
	}

	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @param companyAdress the companyAdress to set
	 */
	public void setCompanyAdress(String companyAdress) {
		this.companyAdress = companyAdress;
	}

	/**
	 * @param phoneNumber the phoneNumber to set
	 */
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	/**
	 * @param homePage the homePage to set
	 */
	public void setHomePage(String homePage) {
		this.homePage = homePage;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @param group the group to set
	 */
	public void setGroup(String group) {
		this.group = group;
	}
	
	/**
	 * @return the imageURL
	 */
	public String getImageURL() {
		return imageURL;
	}

	/**
	 * @param imageURL the imageURL to set
	 */
	public void setImageURL(String imageURL) {
		this.imageURL = imageURL;
	}

	/**
	 * 
	 * @param d
	 * @return La date formatée pour l'enregistrement dans le fichier
	 */
   public static String fileDate(Date d)
   {
	   String temp;
	   temp=String.valueOf(d.getDate())+String.valueOf(d.getMonth())+String.valueOf(d.getHours())+String.valueOf(d.getMinutes())+String.valueOf(d.getSeconds());
	   
	   return temp;
   }
}
